<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="">
  <meta name="format-detection" content="telephone=no">
  <meta name="full-screen" content="yes">
  <meta name="x5-page-mode" content="app">
  <meta name="x5-fullscreen" content="true">
  <meta name="browsermode" content="application">
  <meta content="" name="keywords">
  <meta content="" name="description">
  <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
  <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
  <link rel="stylesheet" href="./js/layer_mobile/need/layer.css">
  <link rel="stylesheet" href="./css/style.css">
  <link rel="stylesheet" href="./iconfont/iconfont.css">
  <title>申请提现</title>
  <style>
    .tips { font-size: 13px; color: #969696; text-align: left; width: 240px; margin: 10px auto 0; }
    .tips code { font-size: 93%; padding: 2px 4px; color: #c7254e; background-color: #f9f2f4; border-radius: 4px; }
  </style>
</head>
<body>
  <div class="page__hd">
    <div class="page__title">申请提现</div>
    <div class="page__desc">您当前账户余额 <b class="theme-color" id='money'>0.00</b> 元</div>
  </div>
  <div class="weui-cells weui-cells_form">
    <div class="weui-cell">
      <div class="weui-cell__bd">
        <input id='fee' class="weui-input" type="number" placeholder="请输入申请金额（元）">
      </div>
    </div>
  </div>
  <button class="weui-btn weui-btn_primary submit-btn" id="appbtn">申请提现</button>
  <div class="tips">
    <div>1. 每天仅能提现<code>一次</code>；</div>
    <div>2. 每次提现金额不低于<code>1元</code>；</div>
    <div>3. 每次提现金额不大于<code>1000元</code>。</div>
  </div>


  <div class="weui-msg__extra-area">
    <div class="weui-footer">
      <p class="weui-footer__text">Copyright © 天空文化传播</p>
    </div>
  </div>


  <script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
  <script src="https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js"></script>
  <script src="./js/tools2.js?ver=2.1"></script>
  <script src="./js/jweixin-1.4.0.js?ver=1.0"></script>
  <script src="./js/layer_mobile/layer.js"></script>
  <script src="./js/layer_mobile/laytpl.js"></script>
  <script>
    // var vConsole = new VConsole();
    var mid = tools.getItem('userInfo').user_code;   // 用户id
    var pid = 0;    // 代理id
    var money = 0;    // 账户余额
    $(function() {
      tools.login(function() {
        getSpeed();
      })

      // 申请
      $('#appbtn').click(function() {
        var apm = Number($('#fee').val());
        if(!valide(apm)) return;

        tools.ajax({
          url: '/proxy/withdraw',
          type: 'POST',
          data: { id: pid, money: apm },
          success: function(res) {
            if(res.code == 0) {
              window.location.replace('./moneySpeed.html');
            } else {
              layer.open({ content: res.msg, skin: 'msg', time: 2 });
            }
          }
        })
      })
    })

    // 验证申请额度
    function valide(m) {
      if(!pid) {
        layer.open({ content: '代理id不能为空', skin: 'msg', time: 2 });
        return false;
      } else if(m > money) {
        layer.open({ content: '账户余额不足', skin: 'msg', time: 2 });
        return false;
      } else if(m < 1) {
        layer.open({ content: '最低申请提现1元', skin: 'msg', time: 2 });
        return false;
      } else if(m > 1000) {
        layer.open({ content: '最高申请提现1000元', skin: 'msg', time: 2 });
        return false;
      }
      return true;
    }


    // 获取申请进度
    function getSpeed() {
      tools.ajax({
        url: "/proxy/" + mid,
        success: function(res) {
          if(res.code == 0) {
            money = res.data.money;
            pid = res.data.id;
            $('#money').html(res.data.money);
          }
        }
      })
    }

    tools.hide();
  </script>
</body>
</html>